package com.sanrenzu.chunbo.ui.vertical.shop;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.adapter.ShopListview;
import com.sanrenzu.chunbo.dao.Collection;
import com.sanrenzu.chunbo.dao.ShopDao;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by My on 2016/9/3.
 */
public class ShopFragment extends Fragment {


    @BindView(R.id.shop_listview)
    ListView shopListview;

    @BindView(R.id.shop_money_main)
    TextView shopMoneyMain;
    @BindView(R.id.shop_btn_jiesuan)
    Button shopBtnJiesuan;

    private ShopListview shopListviewAdapter;
    private Unbinder bind;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_shop, container, false);
        bind = ButterKnife.bind(this, view);
        setView();
        return view;
    }

    private void setView() {
        List<Collection> collections = ShopDao.quaryAll(getActivity());
        shopListviewAdapter = new ShopListview(getActivity(), collections);
        shopListview.setAdapter(shopListviewAdapter);
        shopListviewAdapter.notifyDataSetChanged();

        shopListview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                return false;
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }
}
